/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.center.web.action.report;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import com.sinodata.bsm.center.dao.ReportDao;
import com.sinodata.bsm.center.util.web.Struts2Utils;
import com.sinodata.bsm.center.web.action.BaseAction;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author wangyazhou
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2013-8-16 下午3:44:25          wangyazhou        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class ReportAction extends BaseAction {

    @Autowired
    private ReportDao reportDao;

    private static final long serialVersionUID = 1L;

    /**
     * 主机日报表
     * @return
     */
    public String hostReportDay() {

        try {

            JSONObject json = new JSONObject();
            List<String[]> list = reportDao.getReportData("report_for_host", " order by res_type");
            JSONArray data = new JSONArray();
            for (int i = 0; i < list.size(); i++) {
                String[] strAry = list.get(i);
                JSONObject obj = new JSONObject();
                obj.element("1", wrapper(strAry, 1));
                obj.element("2", wrapper(strAry, 3));
                obj.element("3", wrapper(strAry, 7));
                obj.element("4", wrapper(strAry, 8));
                obj.element("5", wrapper(strAry, 9));
                obj.element("6", wrapper(strAry, 10));
                obj.element("7", wrapper(strAry, 11));
                obj.element("8", wrapper(strAry, 12));
                obj.element("9", wrapper(strAry, 13));
                obj.element("10", wrapper(strAry, 14));
                obj.element("11", wrapper(strAry, 15));
                obj.element("12", wrapper(strAry, 16));
                obj.element("13", wrapper(strAry, 17));
                obj.element("14", wrapper(strAry, 18));
                obj.element("15", toTime(strAry, 5));
                data.add(obj);
            }

            json.element("size", list.size());
            json.element("data", data);

            Struts2Utils.renderText(json.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private String toTime(String[] ary, int num) {
        return ary[num].substring(0, ary[num].length() - 5);
    }

    public String wrapper(String[] ary, int num) {
        return (ary[num] == null || ary[num].length() < 1) ? "-" : ary[num];
    }

    @Override
    public Object getModel() {
        return null;
    }

    @Override
    public String list() throws Exception {
        return null;
    }

    @Override
    public String input() throws Exception {
        return null;
    }

    @Override
    public String save() throws Exception {
        return null;
    }

    @Override
    public String delete() throws Exception {
        return null;
    }

    @Override
    protected void prepareModel() throws Exception {

    }

}
